#ifndef __SINGLETON_H__
#define __SINGLETON_H__

#include <iostream>

using std::cout;
using std::endl;

template <typename T1>
class Singleton
{
public:
    template<typename T>
    static T1*getInstance(T t) {
        if (nullptr == _pInstance) {
            _pInstance = new T1(t);
        }
        return _pInstance;
    }
    static void destroy() {
        if (_pInstance) {
            delete _pInstance;
            _pInstance = nullptr;
        }
    }

private:
    Singleton()
    {
        cout << "Singleton()" << endl;
    }

    ~Singleton() {
        cout << "~Singleton()" << endl;
    }

private:
    static T1* _pInstance;
};

template <typename T1>
T1 *Singleton<T1>::_pInstance = nullptr;

#endif

/* Computer *pc1 = Singleton<Computer>::getInstance("Xiaomi", 6666); */
/* Computer *pc2 = Singleton<Computer>::getInstance("Mac", 8888); */
